﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;

namespace _1042009_1042034
{
    public partial class uctQuanLyLoaiPhong : UserControl
    {
        public uctQuanLyLoaiPhong()
        {
            InitializeComponent();
        }

        int iColStt, iColMaLoaiPhong, iColTenLoaiPhong, iColCheck, iColDonGia;
        List<LoaiPhongDTO> LstLoaiPhong = Business.LoaiPhongService.LayDanhSach();

        protected void CreateColumn()
        {
            this.dgv.Columns.Clear();
            this.dgv.AddTextColumn(true, "STT", "STT");
            this.dgv.AddColumnStt();
            this.dgv.AddTextColumn(true, "MaLoaiPhong", "Mã Loại Phòng");
            this.dgv.AddTextColumn(false, "TenLoaiPhong", "Tên Loại Phòng");
            this.dgv.AddTextColumn(false, "DonGia", "Đơn giá");
            this.dgv.AddCheckBoxColumn("Check", "Check");

            this.iColStt = this.dgv.GetColumIndexByName("STT");
            this.iColMaLoaiPhong = this.dgv.GetColumIndexByName("MaLoaiPhong");
            this.iColTenLoaiPhong = this.dgv.GetColumIndexByName("TenLoaiPhong");
            this.iColCheck = this.dgv.GetColumIndexByName("Check");
            this.iColDonGia = this.dgv.GetColumIndexByName("DonGia");
        }

        void SetUpDataGridView()
        {             
            this.dgv.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
            this.dgv.Location = new Point(0, 0);
            this.dgv.ScrollBars = ScrollBars.Both;
            this.dgv.TopLeftHeaderCell.Value = "Select All";
            this.dgv.BackgroundColor = Color.White;
            DataTable dt = Business.LoaiPhongService.ConvertListLoaiPhongDTOToDataTable(LstLoaiPhong);
            this.dgv.MyDataTable = dt;
            this.dgv.AddRows();
        }

        int iStt = 0;
        void LoadRows(int iRow)
        {
            iStt = this.dgv.iRecord * (this.dgv.iPage - 1) + 1 + iRow;
            this.dgv[this.iColStt, iRow].Value = this.iStt.ToString();
        }
        void ReLoad()
        {
            for (int i = 0; i < this.dgv.Rows.Count; i++)
            {
                this.LoadRows(i);
            }
        }
        private void dgv_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int iColIndex = this.dgv.SelectedCells[0].ColumnIndex;
                int iRowIndex = this.dgv.SelectedCells[0].RowIndex;
                this.dgv.SetRowColor(iRowIndex, MyColor.Edit);

                if (iColIndex != this.iColCheck)
                {
                    this.dgv[this.iColCheck, iRowIndex].Value = "Checked";
                }
            }
            catch { }
        }

        private void uctQuanLyLoaiPhong_Load(object sender, EventArgs e)
        {

            CreateColumn();
            this.SetUpDataGridView();
            this.dgv.DataSource = this.dgv.MyDataTable;
            //this.ReLoad();
        }

       

        
        
    }
}
